package com.huike.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huike.clues.MpService.MpSysMenuService;
import com.huike.clues.domain.dto.MPSysMenuDTO;
import com.huike.clues.domain.dto.MPSysMenuTreeDTO;
import com.huike.clues.domain.vo.MPSysMenuFindByIdVo;
import com.huike.clues.domain.vo.MPSysMenuTreeVo;
import com.huike.clues.domain.vo.RoleMenuTreeAjaxResultVo;
import com.huike.clues.service.ISysMenuService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.entity.SysMenu;
import com.huike.web.result.RoleMenuTreeAjaxResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.huike.common.core.controller.BaseController;

import java.awt.*;
import java.util.List;

@RestController
@Slf4j
@Api(tags = "菜单相关接口")
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController{

    @Autowired
    private ISysMenuService menuService;

    @Autowired
    private MpSysMenuService mpSysMenuService;
    @GetMapping("/list")
    //@PreAuthorize("@ss.hasPermi('system:user:list')")
    // TODO 填写权限信息
    public AjaxResult list(SysMenu sysMenu){
        List<SysMenu> list = menuService.selectMenuList(sysMenu);
        return AjaxResult.success(list);
    }

    /**
     * 新增菜单
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:menu:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MPSysMenuDTO MPSysMenuDTO){
        mpSysMenuService.add(MPSysMenuDTO);
        return AjaxResult.success();
    }

    /**
     * 根据菜单编号获取详细信息
     * @param menuId
     * @return
     */
    @GetMapping("/{menuId}")
    public AjaxResult menuFindById(@PathVariable Long menuId){
        MPSysMenuFindByIdVo mpSysMenuFindByIdVo = mpSysMenuService.menuFindById(menuId);
        return AjaxResult.success(mpSysMenuFindByIdVo);
    }

    /**
     * 删除菜单
     * @param menuId
     * @return
     */
    @DeleteMapping("/{menuId}")
    public AjaxResult menuDeleteById(@PathVariable Long menuId){
        mpSysMenuService.menuDeleteById(menuId);
        return AjaxResult.success();
    }

    /**
     *获取菜单下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult  treeselect(MPSysMenuTreeDTO mpSysMenuTreeDTO){
        List<MPSysMenuTreeVo> mpSysMenuTreeVoList = mpSysMenuService.treeselect(mpSysMenuTreeDTO);
        return AjaxResult.success(mpSysMenuTreeVoList);
    }

    /**
     * 加载对应角色菜单列表树
     * @param roleId
     * @return
     */
    @GetMapping("/roleMenuTreeselect/{roleId}")
    public RoleMenuTreeAjaxResultVo roleMenuTreeselect(@PathVariable Long roleId){
        RoleMenuTreeAjaxResultVo roleMenuTreeAjaxResultVo = mpSysMenuService.roleMenuTreeselect(roleId);
        return roleMenuTreeAjaxResultVo;
    }

    @PutMapping
    public AjaxResult updateMenu(@RequestBody MPSysMenuDTO mpSysMenuDTO){
        mpSysMenuService.updateMenu(mpSysMenuDTO);
        return AjaxResult.success();
    }


}
